package main

import "fmt"

/* 数组中两数和，返回指定和的下标 */

func main() {
	var nums []int = []int{1, 2, 4, 7, 9, 12}
	var target int = 19
	r := getSumIndex(nums, target)
	fmt.Print(r)
}

func getSumIndex(nums []int, target int) []int {
	var mapIndex = make(map[int]int)
	for start := 0; start < len(nums); start++ {
		other := target - nums[start]
		if i, ok := mapIndex[other]; ok {
			return []int{i, start}
		}
		mapIndex[nums[start]] = start
	}
	return nil
}
